package edu.tgc.web.controller.file;

import java.util.HashSet;
import java.util.UUID;

import org.abyss.data.specifications.Rule;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;

import edu.tgc.entity.file.FileContract;
import edu.tgc.entity.file.FilePath;
import edu.tgc.web.form.file.FileContractForm;

@Controller
@RequestMapping(value = "file/contract")
public class FileContractController extends AbstractFileResourceController<FileContract, UUID, FileContractForm> {

    @Override
    public Specification<FileContract> buildSearch(FileContractForm form) {
        HashSet<Rule> rules = new HashSet<>();
        String searchKey = form.getSearchKey();
        if (StringUtils.hasText(searchKey)) {
            rules.add(Rule.or(Rule.property("name").contain(searchKey), Rule.property("sn").contain(searchKey)));
        }
        return Rule.and(rules).<FileContract> toSpecification();
    }

    @Override
    public FilePath getPath() {
        return new FilePath("d:\\file\\contract");
    }
}
